using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Tests.Proxies.LazyProxyHelper
{
    [TestClass]
    public class WhenCreatingList
    {
        [TestMethod]
        public void ShouldNotExecuteWhenNotRequired()
        {
            double expectedParameter = 1;
            IList<int> expectedResult = new List<int>(new int[] {1, 2, 3});

            Be.Timvw.Framework.Proxies.LazyProxyHelper.Create<int, double>(delegate(double actualParameter)
            {
                Assert.AreEqual(expectedParameter, actualParameter);
                Assert.Fail("Should not perform this method.");
                return expectedResult;
            }, expectedParameter);
        }

        [TestMethod]
        public void ShouldExecuteWhenRequired()
        {
            double expectedParameter = 1;
            IList<int> expectedResult = new List<int>(new int[] {1, 2, 3});

            IList<int> actualResult = Be.Timvw.Framework.Proxies.LazyProxyHelper.Create<int, double>(delegate(double actualParameter)
            {
                Assert.AreEqual(expectedParameter, actualParameter);
                return expectedResult;
            }, expectedParameter);

            Assert.AreEqual(expectedResult.Count, actualResult.Count);
            for(int i = 0; i < expectedResult.Count; ++i)
            {
                Assert.AreEqual(expectedResult[i], actualResult[i]);
            }
        }
    }
}